/**
 * Mar 14, 2014 - 8:33:46 AM
 */
package elitech.vietnam.weatherfashion.dialog;

import elitech.vietnam.weatherfashion.R;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

/**
 * @author Cong Vo
 *
 */
public class ConfirmDialog extends Dialog implements View.OnClickListener {
	
	OnYesClick mYes;
	OnNoClick mNo;
	
	TextView mContent;
	Button mBtnYes, mBtnNo;
	
	String mMessage;

	private ConfirmDialog(Builder builder) {
		super(builder.context, R.style.Dialog);
		mYes = builder.mYes;
		mNo = builder.mNo;
		mMessage = builder.mMessage;
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.confirm_dialog);
		setCancelable(false);
		
		mContent = (TextView) findViewById(R.id.confirmdialog_textMessage);
		mBtnYes = (Button) findViewById(R.id.confirmdialog_btnYes);
		mBtnNo = (Button) findViewById(R.id.confirmdialog_btnNo);
		
		mBtnYes.setOnClickListener(this);
		mBtnNo.setOnClickListener(this);
		
		mContent.setText(mMessage);
	}
	
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.confirmdialog_btnYes:
			if (mYes != null)
				mYes.doClick();
			break;
		case R.id.confirmdialog_btnNo:
			if (mNo != null)
				mNo.doClick();
			break;

		default:
			break;
		}
		dismiss();
	}
	
	public interface OnYesClick {
		public void doClick();
	}
	
	public interface OnNoClick {
		public void doClick();
	}
	
	public static class Builder {
		OnYesClick mYes;
		OnNoClick mNo;
		String mMessage;
		Context context;
		boolean cancelable = true;
		
		public Builder(Context context) {
			this.context = context;
		}
		
		public Builder setMessage(String mess) {
			mMessage = mess;
			return this;
		}
		
		public Builder setYesClick(OnYesClick click) {
			this.mYes = click;
			return this;
		}
		
		public Builder setNoClick(OnNoClick click) {
			this.mNo = click;
			return this;
		}
		
		public ConfirmDialog build() {
			return new ConfirmDialog(this);
		}
	}
}
